package servletTest;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by v on 17-3-27.
 */
@WebServlet(value = "/Servlet",name = "Servlet")
public class Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String user=request.getParameter("user");
        String pwd=request.getParameter("pwd");

        System.out.println("in");

        //如果判断密码正确则保存其相应的ip地址，允许其进入登录层
        if(user!=null&&pwd!=null
                &&user.equals("admin")&&pwd.equals("admin")){
            String ip=request.getRemoteAddr();

            request.getSession().setAttribute(ip,user);
        }

        response.sendRedirect("/testjsp/4.11/logIn.html");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}